﻿using System.Collections.ObjectModel;
using System.Windows.Input;
using WhiteFlow.DevTrackingTool.UI.Models;
using WhiteFlow.Wpf.Common.Commands;

namespace WhiteFlow.DevTrackingTool.UI.ViewModels
{
    /// <summary>
    /// The ViewModel that manages and manipulates a customers list.
    /// </summary>
    public class CustomersListViewModel : WorksheetChildViewModelBase
    {
        #region Constants

        #endregion

        #region Fields

        private ICommand createCustomersListCommand;

        private ICommand addCustomerCommand;

        private ICommand deleteSelectedCustomerCommand;

        #endregion

        #region Commands

        public ICommand CreateCustomersListCommand
        {
            get
            {
                if (createCustomersListCommand == null)
                {
                    createCustomersListCommand = new DelegateCommand(
                        CreateCustomersList,
                        CanCreateCustomersList);
                }

                return createCustomersListCommand;
            }
        }

        public ICommand AddCustomerCommand
        {
            get
            {
                if (addCustomerCommand == null)
                {
                    addCustomerCommand = new DelegateCommand(
                        AddCustomer,
                        CanAddCustomer);
                }

                return addCustomerCommand;
            }
        }

        public ICommand DeleteSelectedCustomerCommand
        {
            get
            {
                if (deleteSelectedCustomerCommand == null)
                {
                    deleteSelectedCustomerCommand = new DelegateCommand(
                        DeleteSelectedCustomer,
                        CanDeleteSelectedCustomer);
                }

                return deleteSelectedCustomerCommand;
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="CustomersListViewModel"/> class.
        /// </summary>
        /// <param name="ownerWorksheetViewModel">The <see cref="WorksheetViewModel"/> instance that owns this instance.</param>
        public CustomersListViewModel(WorksheetViewModel ownerWorksheetViewModel) : base(ownerWorksheetViewModel) { }

        #endregion

        #region Commands Implementations

        private void CreateCustomersList()
        {
            OwnerWorksheetViewModel.Worksheet.Customers = new ObservableCollection<Customer>();
        }

        private bool CanCreateCustomersList()
        {
            return (OwnerWorksheetViewModel.Worksheet.Customers == null);
        }

        private void AddCustomer()
        {
            Customer customer = new Customer();
            ownerWorksheetViewModel.Worksheet.Customers.Add(customer);
        }

        private bool CanAddCustomer()
        {
            return (ownerWorksheetViewModel.Worksheet.Customers != null);
        }

        private void DeleteSelectedCustomer()
        {

        }

        private bool CanDeleteSelectedCustomer()
        {
            return false;
        }

        #endregion
    }
}